<?php

class Usr extends Zend_Db_Table
{
    protected $_name = 'ADMAUT.USR';
    protected $_primary = array('USRLOG','USRAPP');
    
    public static function findlog($db, $app, $login)
    {
    	$usr = new self();
    	$select = $usr->select();
    	$select->from($usr,array('USRID','USRPRN','USRNOM','USRPRF','USRAPP','USRLOG'))
    		   ->where('USRLOG = ?', $login);
    	$rows =  $usr->fetchall($select)->toarray();
    	if ($rows) {	   
    		$result['USER'] = array('USRID'=>$rows[0]['USRID'],'USRPRN'=>$rows[0]['USRPRN'],'USRNOM'=>$rows[0]['USRNOM'],'USRLOG'=>$rows[0]['USRLOG']);
    		foreach ($rows as $row) {
    			$result[$db][$row['USRAPP']] = $row['USRPRF'];
    		}
    	}
    	else {
    		$result = array('USER'=>array('USRID'=>' ','USRPRN'=>' ','USRNOM'=>' ','USRLOG'=>$login), $db=>array($app=>'invite'));
    	}
    	return $result;	
    }
public static function finddbd($db, $app, $login)
    {
    	$usr = new self();
    	$select = $usr->select();
    	$select->from($usr,array('USRID','USRPRN','USRNOM','USRPRF','USRAPP','USRLOG'))
    		   ->where('USRLOG = ?', $login);
    	$rows =  $usr->fetchall($select)->toarray();
    	$result = array();   
    	if ($rows) {
    		foreach ($rows as $row) {
    			$result[$db][$row['USRAPP']] = $row['USRPRF'];
    		}
    	}
    	else {
    		$result[$db][$app] = 'invite';
    	}
    	return $result;	
    }
}

?>
